package com.jh3502.vivo.function.dialog;

import android.support.annotation.NonNull;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.jh3502.vivo.base.BaseCallback;
import com.jh3502.vivo.base.BaseJson;
import com.jh3502.vivo.base.BasePresenter;
import com.jh3502.vivo.base.BaseView;

import java.util.List;

/**
 * @author harisucici
 * @date 2017/6/19
 */

public class CarTypePresenter extends BasePresenter<CarTypePresenter.CarTypeView> {
    CarTypeModel mCarTypeModel;

    CarTypeView mCarTypeView;


    public void setCarTypeView(CarTypeView mCarTypeView) {
        this.mCarTypeView = mCarTypeView;

    }

    public void toFindTraffic() {
        mCarTypeView.showLoadingDialog();
        if (mCarTypeModel == null) {
            mCarTypeModel = new CarTypeModel(mCarTypeView.getActContext());
        }

        mCarTypeModel.findTraffic(new BaseCallback(mCarTypeView) {
            @Override
            public void responseSuccess(@NonNull BaseJson baseJson) {
                List<CarTypeBean> datas = new Gson().fromJson(baseJson.getObj().toString(),
                        new TypeToken<List<CarTypeBean>>() {
                        }.getType());

                mCarTypeView.findTrafficSuccess(datas);
            }
        });
    }

    @Override
    public void cancelCall() {

    }

    public interface CarTypeView extends BaseView {
        void findTrafficSuccess(List<CarTypeBean> datas);
    }
}
